package com.pl.study.mapreduce;

import com.pl.study.mapreduce.vo.FlowVo;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * <p>
 *
 * @Description: reduce
 * </p>
 * @ClassName FlowStatisticReduce
 * @Author pl
 * @Date 2022/3/10
 * @Version V1.0.0
 */
public class FlowStatisticReduce extends Reducer<Text, FlowVo,Text, FlowVo> {
    private FlowVo outV = new FlowVo();

    @Override
    protected void reduce(Text key, Iterable<FlowVo> values, Context context) throws IOException, InterruptedException {

        long totalUp = 0;
        long totaldown = 0;
        long sumFlow = 0;

        for (FlowVo value : values) {
            totalUp += value.getUpFlow();
            totaldown += value.getDownFlow();
            sumFlow += value.getSumFlow();
        }

        outV.setUpFlow(totalUp);
        outV.setDownFlow(totaldown);
        outV.setSumFlow(sumFlow);

        context.write(key, outV);
    }
}